package server;

import java.util.ArrayList;

public class SecurityKernel {
	
	public SecurityKernel(){
	}
	
	public boolean mayRead(User user, Journal j){
		switch(user.getClasss()){
			case User.GOVT: return true;
			case User.DOCTOR: return j.isAssociated(user.getName()) ? true : user.getDivision().equals(j.getDivision());
			case User.NURSE: return j.isAssociated(user.getName()) ? true : user.getDivision().equals(j.getDivision());
			case User.PATIENT: return j.getPatientName().equals(user.getName());
		}
		return false;
	}
	
	public boolean mayEdit(User user, Journal j){
		switch(user.getClasss()){
			case User.GOVT: return false;
			case User.DOCTOR: return j.isAssociated(user.getName());
			case User.NURSE: return j.isAssociated(user.getName());
			case User.PATIENT: return false;
		}
		return false;
	}
	
	public boolean mayRemove(User user, Journal j){
		switch(user.getClasss()){
			case User.GOVT: return true;
			case User.DOCTOR: return false;
			case User.NURSE: return false;
			case User.PATIENT: return false;
		}
		return false;
	}
	
	public boolean mayCreate(User user, Patient p){
		switch(user.getClasss()){
			case User.GOVT: return false;
			case User.DOCTOR: return p.isAssociated(user.getName());
			case User.NURSE: return false;
			case User.PATIENT: return false;
		}
		return false;
	}
}
